import Router from 'koa-router'
import dbConfig from '../config/sql-server'
import {successStatus} from '../utils/status'
import config from '../config/config'
const router = new Router()

router.get('/', async (ctx) => {
  let data  = await new Promise((resolve,reject) => {
    dbConfig("select * from t_user",[], (err,data) => {
      if (err) return reject(err)
      resolve(data)
    })
  })
  successStatus.RESULT.data = data
  ctx.body = successStatus.RESULT
})
router.get("/banner",async (ctx) => {
  let data  = await new Promise((resolve,reject) => {
    dbConfig("select * from banner",[], (err,data) => {
      if (err) return reject(err)
      data.map(val => {
        val.imgUrl = `http://localhost:${config.port}` + val.imgUrl
      })
      resolve(data)
    })
  })
  successStatus.RESULT.data = data
  ctx.body = successStatus.RESULT
})

router.get("/list",(ctx) => {
  ctx.body = "用户列表"
})

export default router